package dao;

import com.lee.StudentApplication;
import com.lee.dao.StudentDao;
import com.lee.domain.Student;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.List;


// 需要启动srpingboot StudentApplication
@SpringBootTest(classes = StudentApplication.class)
public class StudentDaoTestCase {
    @Autowired
    private StudentDao studentDao;

    @Test
    void testGetStudentById() {
        System.out.println(studentDao.getStudentById(1));
    }

    @Test
    void testSaveStudent() {
        Student student = new Student();
        student.setId(1001);
        student.setName("nini");
        student.setAge("20");
        student.setSex("女");
        student.setMajor("表演");
        studentDao.insert(student); // 这里明显是错的 StundentDao是类名！ studentDao才是变量
    }

    @Test
    void testUpdateStudent() {
        Student student = new Student();
        student.setId(1);
        student.setName("lili");
        student.setAge("20");
        student.setSex("女");
        student.setMajor("表演");
        studentDao.update(student);
    }

    @Test
    void testDelectStudentById() {
        studentDao.delete(1001);
    }

    @Test
    void testGetAllStudent() {
        List<Student> students = studentDao.selectAll();
        for (int i = 0; i < students.size(); i++) {
            System.out.println(students.get(i));
        }
    }
}
